package com.zhugang.week01;

/**
 * @program algorithms
 * @description: straight
 * @author: chanzhugang
 * @create: 2022/05/21 20:35
 */
public class Straight2 {

    public static void main(String[] args) {
        Straight2 straight2 = new Straight2();
        int[] nums = new int[]{2, 2, 3, 4, 5};
        boolean flag = straight2.isStraight(nums);
        System.out.println(flag);
    }

    /**
     * 剑指offer61.扑克牌中的顺子，
     *
     * @param nums
     * @return
     */
    public boolean isStraight(int[] nums) {
        // 不能重复；max - min < 5 ; 排除0
        int max = -1;
        int min = 20;
        boolean[] dump = new boolean[14];
        for (int num : nums) {
            if (num != 0) {
                if (dump[num]) {
                    return false;
                } else {
                    dump[num] = true;
                }
                if (num > max) max = num;
                if (num < min) min = num;
            }
        }
        return max - min < 5;
    }
}